var curry = require('curry');


function fmt(format, dateIn) {
    let dateValue = new Date(dateIn);
    var date = {
        "M+": dateValue.getMonth() + 1,
        "d+": dateValue.getDate(),
        "h+": dateValue.getHours(),
        "m+": dateValue.getMinutes(),
        "s+": dateValue.getSeconds(),
        "q+": Math.floor((dateValue.getMonth() + 3) / 3),
        "S+": dateValue.getMilliseconds()
    };
    if (/(y+)/i.test(format)) {
        format = format.replace(RegExp.$1, (dateValue.getFullYear() + '').substr(4 - RegExp.$1.length));
    }
    for (var k in date) {
        if (new RegExp("(" + k + ")").test(format)) {
            format = format.replace(RegExp.$1, RegExp.$1.length == 1
                ? date[k] : ("00" + date[k]).substr(("" + date[k]).length));
        }
    }
    return format;
}

const fmtCurry = curry(fmt);

const full = fmtCurry("yyyy-MM-dd hh:mm:ss SSS");
const hms = fmtCurry("hh:mm:ss SSS");

module.exports = {full, hms};

